package com.engineering.elink.hessian.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.engineering.elink.dao.UserMapper;
import com.engineering.elink.hessian.AuthHessianService;
import com.engineering.elink.service.TokenAuthenticationService;

public class AuthHessianServiceImpl implements AuthHessianService{

	@Autowired
	private TokenAuthenticationService tokenAuthenticationService;
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public synchronized String checkAuthToken(String seed, String authToken) {
		return tokenAuthenticationService.getAuthTokenInfo(seed, authToken);
	}

	@Override
	public synchronized Map<String,Object> getUserInfo(String userId) {
		// TODO Auto-generated method stub
		return userMapper.selectByUserId(userId);
	}

//	@Override
//	public Map<String, Object> checkAuth(HttpServletRequest request) {
//		Cookie seedCookie = CookieUtil.getCookieByName(request, "seed");
//		Cookie authTokenCookie = CookieUtil.getCookieByName(request, "authToken");
//		String seed = null;
//		String authToken = null;
//		if (seedCookie != null && authTokenCookie != null) {
//			seed = seedCookie.getValue();
//			authToken = authTokenCookie.getValue();
//			if (seed != null && authToken != null) {
//				String userId = tokenAuthenticationService.getAuthTokenInfo(seed, authToken);
//				System.out.println("seed="+seed +"&&authToken="+authToken);
//				if (userId != null) {
//					Map<String,Object> userInfo = userMapper.selectByUserId(userId);
//					if (userInfo != null) {
//						 return userInfo;
//					}
//				}
//			}
//		}
//		return null;
//	}
	@Override
	public Map<String, Object> checkAuth(String seed, String authToken,
			String path) {
		// TODO Auto-generated method stub
		String userId = tokenAuthenticationService.getAuthTokenInfo(seed, authToken);
		if (userId != null) {
			 return userMapper.selectByUserId(userId);
		}
		return null;
	}
}
